//
//  ViewController3.m
//  Test3
//
//  Created by 王冲 on 2019/1/31.
//  Copyright © 2019年 JK科技有限公司. All rights reserved.
//

#import "ViewController3.h"

@interface ViewController3 ()

@end

@implementation ViewController3

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor yellowColor];
    
    self.title = @"ViewController3";
    
    UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake(50, 100, [UIScreen mainScreen].bounds.size.width-100, 50)];
    [button2 setBackgroundColor:[UIColor brownColor]];
    [button2 setTitle:@"返回自己的app" forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];
}

-(void)click{
    
    NSString *urlStr = [NSString stringWithFormat:@"%@://",self.urlString];
    
    NSURL *url = [NSURL URLWithString:urlStr];
    
    // 注意: 跳转之前, 使用 canOpenURL: 判断是否可以跳转(这里我们模仿微信，n不去判断了，如果是我们自己写的两个app，记得在彼此的白名单添加彼此的scheme)
    // if (![[UIApplication sharedApplication]canOpenURL:url]) {
    //     return;
    // }
    
    if (@available(iOS 10.0, *)){
        
        [[UIApplication sharedApplication]openURL:url options:@{UIApplicationOpenURLOptionsSourceApplicationKey:@YES} completionHandler:^(BOOL success) {
            
            if (success) {
                NSLog(@"10以后可以跳转url");
            }else{
                NSLog(@"10以后不可以跳转url");
            }
        }];
    }else{
        
        BOOL success = [[UIApplication sharedApplication]openURL:url];
        
        if (success) {
            NSLog(@"10以前可以跳转url");
        }else{
            NSLog(@"10以前不可以跳转url");
        }
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
